package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.ef.constant.StatusType;
import com.ef.dao.ClassLevelDao;
import com.ef.domain.ClassLevel;
import com.ef.service.ClassLevelService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class ClassLevelServiceImpl extends BaseServiceImpl implements
		ClassLevelService {

	private ClassLevelDao classLevelDao;

	public PaginationSupport<ClassLevel> findByExample(
			CustomExample<ClassLevel> example, int startIndex, int pageSize) {

		return classLevelDao.findPageByExample(example, startIndex, pageSize);
	}

	public void saveOrUpdate(ClassLevel entity) {
		classLevelDao.saveOrUpdate(entity);
	}

	public void delete(ClassLevel entity) {
		entity.setStatus(StatusType.INVALID);
		classLevelDao.update(entity);
	}

	public ClassLevel findById(Long id) {
		return classLevelDao.findById(id);
	}

	public List<ClassLevel> findALL() {
		DetachedCriteria criteria = DetachedCriteria.forClass(ClassLevel.class);
		criteria.add(Restrictions.eq("status", StatusType.VALID));
		return classLevelDao.findAllByCriteria(criteria);

	}

	public List<ClassLevel> findALLValid() {
		DetachedCriteria criterion = DetachedCriteria
				.forClass(ClassLevel.class);
		criterion.add(Restrictions.eq("status", StatusType.VALID));
		return classLevelDao.findAllByCriteria(criterion);
	}

	public List<ClassLevel> findByName(String name) {
		DetachedCriteria criterion = DetachedCriteria
				.forClass(ClassLevel.class);
		criterion.add(Restrictions.eq("name", name));
		criterion.add(Restrictions.eq("status", StatusType.VALID));
		return classLevelDao.findAllByCriteria(criterion);
	}

	public ClassLevelDao getClassLevelDao() {
		return classLevelDao;
	}

	public void setClassLevelDao(ClassLevelDao classLevelDao) {
		this.classLevelDao = classLevelDao;
	}

}
